import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/routes/routes.dart';
import 'package:cbec_app/utils/ThemeConfig.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:cbec_app/utils/logger.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

///店铺装修-商品搜索框
class DecorationSearchInput extends StatefulWidget {
  ///搜索框配置
  final Map<String, dynamic> info;

  const DecorationSearchInput({super.key, required this.info});

  @override
  State<DecorationSearchInput> createState() => _DecorationSearchInputState();
}

class _DecorationSearchInputState extends State<DecorationSearchInput> {
  FocusNode focusNode = FocusNode();

  @override
  void initState() {
    super.initState();
    focusNode.unfocus();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: widget.info['color'] != ''
          ? Tools.fromHex(widget.info['color'])
          : Colors.transparent,
      alignment: Alignment.center,
      child: Container(
        width: 359.w,
        height: (widget.info['border_style_height'] as int).toDouble(),
        child: CupertinoTextField(
          readOnly: true,
          prefix: const Padding(
            padding: EdgeInsets.only(left: 11),
            child: Icon(Icons.search, color: ThemeConfig.themeColor),
          ),
          placeholder: '搜索商品',
          placeholderStyle: setTextStyle(
              10,
              FontWeight.w300,
              widget.info['text_color'] != ''
                  ? Tools.fromHex(widget.info['text_color'])
                  : ThemeConfig.subTextColor),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(getRadius())),
               color: widget.info['border_style_color'] != ''
                      ? Tools.fromHex(widget.info['border_style_color'])
                      : Colors.transparent),
          textAlign: widget.info['text_align_method'] == '0'
              ? TextAlign.left
              : TextAlign.center,
          style: setTextStyle(
              13,
              FontWeight.w300,
              widget.info['text_color'] != ''
                  ? Tools.fromHex(widget.info['text_color'])
                  : ThemeConfig.mainTextColor),
          onChanged: (value) => {},
          onTap: () {
            focusNode.unfocus();
            Get.toNamed(Routes.search);
          },
        ),
      ),
    );
  }

  ///获取边框圆角
  double getRadius() {
    switch (widget.info['border_style_method']) {
      case '1': //圆形
        return (widget.info['border_style_height'] as int).toDouble();
      case '0': //方形
      default:
        return 4.0;
    }
  }
}
